{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周内容：柱状图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基本柱状图绘制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1001\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1001\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1001\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 垂直柱状图\n",
    "\n",
    "* 绘制方法\n",
    "> vbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method vbar in module bokeh.plotting.figure:\n",
      "\n",
      "vbar(x, width, top, bottom=0, *, fill_alpha=1.0, fill_color='gray', hatch_alpha=1.0, hatch_color='black', hatch_extra={}, hatch_pattern=None, hatch_scale=12.0, hatch_weight=1.0, line_alpha=1.0, line_cap='butt', line_color='black', line_dash=[], line_dash_offset=0, line_join='bevel', line_width=1, name=None, tags=[], **kwargs) method of bokeh.plotting.figure.Figure instance\n",
      "    Configure and add :class:`~bokeh.models.glyphs.VBar` glyphs to this Figure.\n",
      "    \n",
      "    Args:\n",
      "        x (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The x-coordinates of the centers of the vertical bars.\n",
      "    \n",
      "        width (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The widths of the vertical bars.\n",
      "    \n",
      "        top (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The y-coordinates of the top edges.\n",
      "    \n",
      "        bottom (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The y-coordinates of the bottom edges.\n",
      "    \n",
      "            (default: 0)\n",
      "    \n",
      "    \n",
      "    Keyword args:\n",
      "        fill_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The fill alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        fill_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The fill color values for the vertical bars.\n",
      "    \n",
      "            (default: gray)\n",
      "    \n",
      "        hatch_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        hatch_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The hatch color values for the vertical bars.\n",
      "    \n",
      "            (default: black)\n",
      "    \n",
      "        hatch_extra (:class:`~bokeh.core.properties.Dict` ( :class:`~bokeh.core.properties.String` , :class:`~bokeh.core.properties.Instance` ( :class:`~bokeh.models.textures.Texture`  ) )):\n",
      "            The hatch extra values for the vertical bars.\n",
      "    \n",
      "            (default: {})\n",
      "    \n",
      "        hatch_pattern (:class:`~bokeh.core.properties.HatchPatternSpec` ):\n",
      "            The hatch pattern values for the vertical bars.\n",
      "    \n",
      "        hatch_scale (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch scale values for the vertical bars.\n",
      "    \n",
      "            (default: 12.0)\n",
      "    \n",
      "        hatch_weight (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch weight values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        line_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The line alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        line_cap (:class:`~bokeh.core.properties.Enum` ( :class:`~bokeh.core.enums.LineCap`  ), optional):\n",
      "            The line cap values for the vertical bars.\n",
      "    \n",
      "            (default: butt)\n",
      "    \n",
      "        line_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The line color values for the vertical bars.\n",
      "    \n",
      "            (default: black)\n",
      "    \n",
      "        line_dash (:class:`~bokeh.core.properties.DashPattern` ):\n",
      "            The line dash values for the vertical bars.\n",
      "    \n",
      "            (default: [])\n",
      "    \n",
      "        line_dash_offset (:class:`~bokeh.core.properties.Int` ):\n",
      "            The line dash offset values for the vertical bars.\n",
      "    \n",
      "            (default: 0)\n",
      "    \n",
      "        line_join (:class:`~bokeh.core.properties.Enum` ( :class:`~bokeh.core.enums.LineJoin`  ), optional):\n",
      "            The line join values for the vertical bars.\n",
      "    \n",
      "            (default: bevel)\n",
      "    \n",
      "        line_width (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The line width values for the vertical bars.\n",
      "    \n",
      "            (default: 1)\n",
      "    \n",
      "        name (:class:`~bokeh.core.properties.String` ):\n",
      "            An arbitrary, user-supplied name for this model.\n",
      "        \n",
      "            This name can be useful when querying the document to retrieve specific\n",
      "            Bokeh models.\n",
      "        \n",
      "            .. code:: python\n",
      "        \n",
      "                >>> plot.circle([1,2,3], [4,5,6], name=\"temp\")\n",
      "                >>> plot.select(name=\"temp\")\n",
      "                [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]\n",
      "        \n",
      "            .. note::\n",
      "                No uniqueness guarantees or other conditions are enforced on any names\n",
      "                that are provided, nor is the name used directly by Bokeh for any\n",
      "                reason.\n",
      "    \n",
      "        tags (:class:`~bokeh.core.properties.List` ( :class:`~bokeh.core.properties.Any`  )):\n",
      "            An optional list of arbitrary, user-supplied values to attach to this\n",
      "            model.\n",
      "        \n",
      "            This data can be useful when querying the document to retrieve specific\n",
      "            Bokeh models:\n",
      "        \n",
      "            .. code:: python\n",
      "        \n",
      "                >>> r = plot.circle([1,2,3], [4,5,6])\n",
      "                >>> r.tags = [\"foo\", 10]\n",
      "                >>> plot.select(tags=['foo', 10])\n",
      "                [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]\n",
      "        \n",
      "            Or simply a convenient way to attach any necessary metadata to a model\n",
      "            that can be accessed by ``CustomJS`` callbacks, etc.\n",
      "        \n",
      "            .. note::\n",
      "                No uniqueness guarantees or other conditions are enforced on any tags\n",
      "                that are provided, nor are the tags used directly by Bokeh for any\n",
      "                reason.\n",
      "    \n",
      "            (default: [])\n",
      "    \n",
      "    \n",
      "    \n",
      "    Other Parameters:\n",
      "        alpha (float, optional) :\n",
      "            An alias to set all alpha keyword arguments at once. (default: None)\n",
      "    \n",
      "            Alpha values must be between 0 (fully transparent) and 1 (fully opaque).\n",
      "    \n",
      "            Any explicitly set values for ``line_alpha``, etc. will override this\n",
      "            setting.\n",
      "    \n",
      "        color (Color, optional) :\n",
      "            An alias to set all color keyword arguments at once. (default: None)\n",
      "    \n",
      "            Acceptable values for colors are described in the `Specifying Colors`_\n",
      "            section of the User's Guide.\n",
      "    \n",
      "            Any explicitly set values for ``line_color``, etc. will override this\n",
      "            setting.\n",
      "    \n",
      "            .. _Specifying Colors: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#specifying-colors\n",
      "    \n",
      "        legend_field (str, optional) :\n",
      "            Specify that the glyph should produce multiple legend entried by\n",
      "            `Grouping in the Browser`_. The value of this parameter is the name of a\n",
      "            column in the data source that should be used or the grouping.\n",
      "    \n",
      "            The grouping is performed *in JavaScript*, at the time time the Bokeh\n",
      "            content is rendered in the browser. If the data is subsequently updated,\n",
      "            the legend will automatically re-group.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Grouping in the Browser: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#automatic-grouping-browser\n",
      "    \n",
      "        legend_group (str, optional) :\n",
      "            Specify that the glyph should produce multiple legend entried by\n",
      "            `Grouping in Python`_. The value of this parameter is the name of a\n",
      "            column in the data source that should be used or the grouping.\n",
      "    \n",
      "            The grouping is performed in Python, before the Bokeh output is sent to\n",
      "            a browser. If the date is subsequently updated, the legend will *not*\n",
      "            automatically re-group.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Grouping in Python: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#automatic-grouping-python\n",
      "    \n",
      "        legend_label (str, optional) :\n",
      "            Specify that the glyph should produce a single `Basic Legend Label`_ in\n",
      "            the legend. The legend entry is labeled with exactly the text supplied\n",
      "            here.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Basic Legend Label: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#basic-legend-label\n",
      "    \n",
      "        muted (bool, optionall) :\n",
      "            Whether the glyph should be rendered as muted (default: False)\n",
      "    \n",
      "            For this to be useful, an ``muted_glyph`` must be configured on the\n",
      "            returned ``GlyphRender``. This can be done by explicitly creating a\n",
      "            ``Glyph`` to use, or more simply by passing e.g. ``muted_color``, etc.\n",
      "            to this glyph function.\n",
      "    \n",
      "        name (str, optional) :\n",
      "            An optional user-supplied name to attach to the renderer (default: None)\n",
      "    \n",
      "            Bokeh does not use this value in any way, but it may be useful for\n",
      "            searching a Bokeh document to find a specific model.\n",
      "    \n",
      "        source (ColumnDataSource, optional) :\n",
      "            A user-supplied data source. (defatult: None)\n",
      "    \n",
      "            If not supplied, Bokeh will automatically construct an internal\n",
      "            ``ColumnDataSource`` with default column names from the coordinates and\n",
      "            other arguments that were passed-in as literal list or array values.\n",
      "    \n",
      "            If supplied, Bokeh will use the supplied data source to drive the glyph.\n",
      "            In this case, literal list or arrays may not be used for coordinates or\n",
      "            other arguments. Only singular fixed valued (e.g. ``x=10``) or column\n",
      "            names in the data souce (e.g. ``x=\"time\"``) are permitted.\n",
      "    \n",
      "        view (CDSView, optional) :\n",
      "            A view for filtering the data source. (default: None)\n",
      "    \n",
      "        visible (bool, optional) :\n",
      "            Whether the glyph should be rendered. (default: True)\n",
      "    \n",
      "        x_range_name (str, optional) :\n",
      "            The name of an extra range to use for mapping x-coordinates.\n",
      "            (default: None)\n",
      "    \n",
      "            If not supplied, then the default ``y_range`` of the plot will be used\n",
      "            for coordinate mapping.\n",
      "    \n",
      "        y_range_name (str, optional) :\n",
      "            The name of an extra range to use for mapping y-coordinates.\n",
      "            (default: None)\n",
      "    \n",
      "            If not supplied, then the default ``y_range`` of the plot will be used\n",
      "            for coordinate mapping.\n",
      "    \n",
      "        level (RenderLevel, optional) :\n",
      "            Specify the render level order for this glyph.\n",
      "    \n",
      "    \n",
      "    \n",
      "    It is also possible to set the color and alpha parameters of extra glyphs for\n",
      "    selection, nonselection, hover, or muted. To do so, add the relevane prefix to\n",
      "    any visual parameter. For example, pass ``nonselection_alpha`` to set the line\n",
      "    and fill alpha for nonselect, or ``hover_fill_alpha`` to set the fill alpha for\n",
      "    hover. See the `Glyphs`_ section od the User's Guide for full details.\n",
      "    \n",
      "    .. _Glyphs: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#glyphs\n",
      "    \n",
      "    Returns:\n",
      "        :class:`~bokeh.models.renderers.GlyphRenderer`\n",
      "    \n",
      "    \n",
      "    Examples:\n",
      "    \n",
      "        .. bokeh-plot::\n",
      "            :source-position: above\n",
      "    \n",
      "            from bokeh.plotting import figure, output_file, show\n",
      "    \n",
      "            plot = figure(plot_width=300, plot_height=300)\n",
      "            plot.vbar(x=[1, 2, 3], width=0.5, bottom=0, top=[1,2,3], color=\"#CAB2D6\")\n",
      "    \n",
      "            show(plot)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(p.vbar)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"dae6f619-627f-425a-9515-3d39daa138c4\" data-root-id=\"1002\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"77b33c36-a678-4126-a330-b12a1d882369\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1011\"}],\"center\":[{\"id\":\"1014\"},{\"id\":\"1018\"}],\"left\":[{\"id\":\"1015\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1036\"}],\"title\":{\"id\":\"1039\"},\"toolbar\":{\"id\":\"1026\"},\"x_range\":{\"id\":\"1003\"},\"x_scale\":{\"id\":\"1007\"},\"y_range\":{\"id\":\"1005\"},\"y_scale\":{\"id\":\"1009\"}},\"id\":\"1002\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data\":{\"top\":[1.2,2.5,3.7],\"x\":[1,2,3]},\"selected\":{\"id\":\"1044\"},\"selection_policy\":{\"id\":\"1045\"}},\"id\":\"1033\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"source\":{\"id\":\"1033\"}},\"id\":\"1037\",\"type\":\"CDSView\"},{\"attributes\":{\"formatter\":{\"id\":\"1043\"},\"ticker\":{\"id\":\"1012\"}},\"id\":\"1011\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1003\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1007\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1041\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1005\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data_source\":{\"id\":\"1033\"},\"glyph\":{\"id\":\"1034\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1035\"},\"selection_glyph\":null,\"view\":{\"id\":\"1037\"}},\"id\":\"1036\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1012\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1011\"},\"ticker\":null},\"id\":\"1014\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1041\"},\"ticker\":{\"id\":\"1016\"}},\"id\":\"1015\",\"type\":\"LinearAxis\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1019\"},{\"id\":\"1020\"},{\"id\":\"1021\"},{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"}]},\"id\":\"1026\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1016\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1044\",\"type\":\"Selection\"},{\"attributes\":{\"axis\":{\"id\":\"1015\"},\"dimension\":1,\"ticker\":null},\"id\":\"1018\",\"type\":\"Grid\"},{\"attributes\":{\"overlay\":{\"id\":\"1025\"}},\"id\":\"1021\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"red\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1035\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1025\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1045\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1022\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"ResetTool\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1039\",\"type\":\"Title\"},{\"attributes\":{\"fill_color\":{\"value\":\"red\"},\"line_color\":{\"value\":\"red\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1034\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1043\",\"type\":\"BasicTickFormatter\"}],\"root_ids\":[\"1002\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"77b33c36-a678-4126-a330-b12a1d882369\",\"root_ids\":[\"1002\"],\"roots\":{\"1002\":\"dae6f619-627f-425a-9515-3d39daa138c4\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1002"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "p = figure(plot_width=400,plot_height=400)\n",
    "\n",
    "p.vbar(\n",
    "    x=[1,2,3],\n",
    "    width=0.5,\n",
    "    bottom=0,\n",
    "    top=[1.2,2.5,3.7],\n",
    "    color=\"red\"\n",
    ")\n",
    "\n",
    "#显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 水平柱状图\n",
    "* 绘制方法\n",
    "> hbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "?? p.hbar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"8dd8f754-a280-4283-836e-d484e199dcda\" data-root-id=\"1101\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"79e6da0d-e751-45fd-ba84-989ec88896b3\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1112\"}],\"center\":[{\"id\":\"1115\"},{\"id\":\"1119\"}],\"left\":[{\"id\":\"1116\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1137\"}],\"title\":{\"id\":\"1102\"},\"toolbar\":{\"id\":\"1127\"},\"x_range\":{\"id\":\"1104\"},\"x_scale\":{\"id\":\"1108\"},\"y_range\":{\"id\":\"1106\"},\"y_scale\":{\"id\":\"1110\"}},\"id\":\"1101\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1106\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data_source\":{\"id\":\"1134\"},\"glyph\":{\"id\":\"1135\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1136\"},\"selection_glyph\":null,\"view\":{\"id\":\"1138\"}},\"id\":\"1137\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_color\":{\"value\":\"navy\"},\"height\":{\"value\":0.5},\"line_color\":{\"value\":\"navy\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1135\",\"type\":\"HBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1152\"},\"ticker\":{\"id\":\"1113\"}},\"id\":\"1112\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1110\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1150\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1152\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1126\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1125\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"navy\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"navy\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1136\",\"type\":\"HBar\"},{\"attributes\":{\"axis\":{\"id\":\"1112\"},\"ticker\":null},\"id\":\"1115\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1113\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1104\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1108\",\"type\":\"LinearScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1126\"}},\"id\":\"1122\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1150\"},\"ticker\":{\"id\":\"1117\"}},\"id\":\"1116\",\"type\":\"LinearAxis\"},{\"attributes\":{\"source\":{\"id\":\"1134\"}},\"id\":\"1138\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1121\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1120\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1153\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1117\",\"type\":\"BasicTicker\"},{\"attributes\":{\"text\":\"\\u6c34\\u5e73\\u67f1\\u72b6\\u56feDemo\"},\"id\":\"1102\",\"type\":\"Title\"},{\"attributes\":{\"axis\":{\"id\":\"1116\"},\"dimension\":1,\"ticker\":null},\"id\":\"1119\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"SaveTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1120\"},{\"id\":\"1121\"},{\"id\":\"1122\"},{\"id\":\"1123\"},{\"id\":\"1124\"},{\"id\":\"1125\"}]},\"id\":\"1127\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1124\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"right\":[1.2,2.5,3.7],\"y\":[1,2,3]},\"selected\":{\"id\":\"1153\"},\"selection_policy\":{\"id\":\"1154\"}},\"id\":\"1134\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1154\",\"type\":\"UnionRenderers\"}],\"root_ids\":[\"1101\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"79e6da0d-e751-45fd-ba84-989ec88896b3\",\"root_ids\":[\"1101\"],\"roots\":{\"1101\":\"8dd8f754-a280-4283-836e-d484e199dcda\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1101"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "p=figure(plot_width=400,plot_height=400,title=\"水平柱状图Demo\")\n",
    "\n",
    "# 绘制\n",
    "p.hbar(\n",
    "    y=[1,2,3],\n",
    "    height=0.5,\n",
    "    left=0,\n",
    "    right=[1.2,2.5,3.7],\n",
    "    color=\"navy\"\n",
    ")\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 案例DOME（1）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"ddb8a0f5-6738-4ba8-baed-ee39ace432a0\" data-root-id=\"1205\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"029283fa-f666-4abd-b903-047a18bb8a5f\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1216\"}],\"center\":[{\"id\":\"1218\"},{\"id\":\"1222\"}],\"left\":[{\"id\":\"1219\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1242\"}],\"title\":{\"id\":\"1206\"},\"toolbar\":{\"id\":\"1231\"},\"x_range\":{\"id\":\"1208\"},\"x_scale\":{\"id\":\"1212\"},\"y_range\":{\"id\":\"1210\"},\"y_scale\":{\"id\":\"1214\"}},\"id\":\"1205\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1226\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1223\",\"type\":\"PanTool\"},{\"attributes\":{\"source\":{\"id\":\"1204\"}},\"id\":\"1243\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1265\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1229\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"start\":0},\"id\":\"1210\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1217\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1216\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1218\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1263\"},\"ticker\":{\"id\":\"1220\"}},\"id\":\"1219\",\"type\":\"LinearAxis\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1223\"},{\"id\":\"1224\"},{\"id\":\"1225\"},{\"id\":\"1226\"},{\"id\":\"1227\"},{\"id\":\"1228\"},{\"id\":\"1230\"}]},\"id\":\"1231\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1220\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1219\"},\"dimension\":1,\"ticker\":null},\"id\":\"1222\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1212\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"data_source\":{\"id\":\"1204\"},\"glyph\":{\"id\":\"1240\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1241\"},\"selection_glyph\":null,\"view\":{\"id\":\"1243\"}},\"id\":\"1242\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data\":{\"counts\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"1266\"},\"selection_policy\":{\"id\":\"1267\"}},\"id\":\"1204\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"text\":\"Fruits Counts\"},\"id\":\"1206\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1214\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1263\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1224\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1228\",\"type\":\"HelpTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1265\"},\"ticker\":{\"id\":\"1217\"}},\"id\":\"1216\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1241\",\"type\":\"VBar\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"1230\",\"type\":\"HoverTool\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"1208\",\"type\":\"FactorRange\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1240\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1266\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1267\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"overlay\":{\"id\":\"1229\"}},\"id\":\"1225\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1227\",\"type\":\"ResetTool\"}],\"root_ids\":[\"1205\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"029283fa-f666-4abd-b903-047a18bb8a5f\",\"root_ids\":[\"1205\"],\"roots\":{\"1205\":\"ddb8a0f5-6738-4ba8-baed-ee39ace432a0\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1205"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "\n",
    "# 数据准备（名称和值）\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "counts = [5, 3, 4, 2, 4, 6]\n",
    "\n",
    "# 数据源准备\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        x = fruits,\n",
    "        counts = counts\n",
    "    )\n",
    ") # 尝试鼠标移入显示数值\n",
    "TOOLTIPS = [\n",
    "    (\"count\",\"@counts\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=fruits,\n",
    "    plot_height=350,\n",
    "    title=\"Fruits Counts\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "\n",
    "# 绘制\n",
    "# p.vbar(x=fruits,top=counts,width=0.5)\n",
    "p.vbar(x='x',top='counts',width=0.8,source=source)\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start=0 #条形最低端与x轴的距离\n",
    "# p.legend.location = \"left\"\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using data directory: C:\\Users\\A\\.bokeh\\data\n",
      "Skipping 'CGM.csv' (checksum match)\n",
      "Skipping 'US_Counties.zip' (checksum match)\n",
      "Skipping 'us_cities.json' (checksum match)\n",
      "Skipping 'unemployment09.csv' (checksum match)\n",
      "Skipping 'AAPL.csv' (checksum match)\n",
      "Skipping 'FB.csv' (checksum match)\n",
      "Skipping 'GOOG.csv' (checksum match)\n",
      "Skipping 'IBM.csv' (checksum match)\n",
      "Skipping 'MSFT.csv' (checksum match)\n",
      "Skipping 'WPP2012_SA_DB03_POPULATION_QUINQUENNIAL.zip' (checksum match)\n",
      "Skipping 'gapminder_fertility.csv' (checksum match)\n",
      "Skipping 'gapminder_population.csv' (checksum match)\n",
      "Skipping 'gapminder_life_expectancy.csv' (checksum match)\n",
      "Skipping 'gapminder_regions.csv' (checksum match)\n",
      "Skipping 'world_cities.zip' (checksum match)\n",
      "Skipping 'airports.json' (checksum match)\n",
      "Skipping 'movies.db.zip' (checksum match)\n",
      "Skipping 'airports.csv' (checksum match)\n",
      "Skipping 'routes.csv' (checksum match)\n",
      "Skipping 'haarcascade_frontalface_default.xml' (checksum match)\n"
     ]
    }
   ],
   "source": [
    "import bokeh\n",
    "bokeh.sampledata.download()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 本人实践：基本柱状图\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 数据源准备\n",
    "import pandas as pd\n",
    "df=pd.read_csv('visualization-20190505.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     9678\n",
       "1    11034\n",
       "2     5387\n",
       "3     6038\n",
       "4     4928\n",
       "5     3783\n",
       "Name: Star, dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Star']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Visualization_tools']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Star\n",
    "# Visualization_tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"d4261d7c-fd11-4560-abcc-41d0d864a277\" data-root-id=\"1318\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"56c20d9d-c904-4afc-baef-1533c2f14193\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1329\"}],\"center\":[{\"id\":\"1331\"},{\"id\":\"1335\"}],\"left\":[{\"id\":\"1332\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1355\"}],\"title\":{\"id\":\"1319\"},\"toolbar\":{\"id\":\"1344\"},\"x_range\":{\"id\":\"1321\"},\"x_scale\":{\"id\":\"1325\"},\"y_range\":{\"id\":\"1323\"},\"y_scale\":{\"id\":\"1327\"}},\"id\":\"1318\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1325\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1354\",\"type\":\"VBar\"},{\"attributes\":{\"overlay\":{\"id\":\"1342\"}},\"id\":\"1338\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1332\"},\"dimension\":1,\"ticker\":null},\"id\":\"1335\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1327\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1387\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1388\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1386\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1384\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1329\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1331\",\"type\":\"Grid\"},{\"attributes\":{\"source\":{\"id\":\"1317\"}},\"id\":\"1356\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1333\",\"type\":\"BasicTicker\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1321\",\"type\":\"FactorRange\"},{\"attributes\":{\"text\":\"yy\"},\"id\":\"1319\",\"type\":\"Title\"},{\"attributes\":{\"formatter\":{\"id\":\"1384\"},\"ticker\":{\"id\":\"1333\"}},\"id\":\"1332\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1337\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1336\",\"type\":\"PanTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"star\",\"@star\"]]},\"id\":\"1343\",\"type\":\"HoverTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1317\"},\"glyph\":{\"id\":\"1353\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1354\"},\"selection_glyph\":null,\"view\":{\"id\":\"1356\"}},\"id\":\"1355\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"start\":0},\"id\":\"1323\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1339\",\"type\":\"SaveTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1342\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data\":{\"star\":[9678,11034,5387,6038,4928,3783],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1387\"},\"selection_policy\":{\"id\":\"1388\"}},\"id\":\"1317\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1330\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1336\"},{\"id\":\"1337\"},{\"id\":\"1338\"},{\"id\":\"1339\"},{\"id\":\"1340\"},{\"id\":\"1341\"},{\"id\":\"1343\"}]},\"id\":\"1344\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"star\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1353\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1340\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1341\",\"type\":\"HelpTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1386\"},\"ticker\":{\"id\":\"1330\"}},\"id\":\"1329\",\"type\":\"CategoricalAxis\"}],\"root_ids\":[\"1318\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"56c20d9d-c904-4afc-baef-1533c2f14193\",\"root_ids\":[\"1318\"],\"roots\":{\"1318\":\"d4261d7c-fd11-4560-abcc-41d0d864a277\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1318"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "Visualization_tools = df['Visualization_tools']\n",
    "Star = df['Star']\n",
    "# 数据源准备\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        x = Visualization_tools,\n",
    "        star = Star\n",
    "    )\n",
    ") # 尝试鼠标移入显示数值\n",
    "TOOLTIPS = [\n",
    "    (\"star\",\"@star\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=Visualization_tools,\n",
    "    plot_height=350,\n",
    "    title=\"yy\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "\n",
    "# 绘制\n",
    "# p.vbar(x=fruits,top=counts,width=0.5)\n",
    "p.vbar(x='x',top='star',width=0.8,source=source)\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start=0 #条形最低端与x轴的距离\n",
    "# p.legend.location = \"left\"\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"edec32f7-b670-4908-8bd6-fd3232e66a66\" data-root-id=\"1439\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"bf2dee23-fee2-4042-a5cb-7e56ac381a5c\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1450\"}],\"center\":[{\"id\":\"1452\"},{\"id\":\"1456\"}],\"left\":[{\"id\":\"1453\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1476\"}],\"title\":{\"id\":\"1440\"},\"toolbar\":{\"id\":\"1465\"},\"x_range\":{\"id\":\"1442\"},\"x_scale\":{\"id\":\"1446\"},\"y_range\":{\"id\":\"1444\"},\"y_scale\":{\"id\":\"1448\"}},\"id\":\"1439\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1463\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1457\"},{\"id\":\"1458\"},{\"id\":\"1459\"},{\"id\":\"1460\"},{\"id\":\"1461\"},{\"id\":\"1462\"},{\"id\":\"1464\"}]},\"id\":\"1465\",\"type\":\"Toolbar\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"commits\",\"@commits\"]]},\"id\":\"1464\",\"type\":\"HoverTool\"},{\"attributes\":{\"start\":0},\"id\":\"1444\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1461\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1451\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1458\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1460\",\"type\":\"SaveTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"commits\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1474\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1446\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1516\",\"type\":\"Selection\"},{\"attributes\":{\"overlay\":{\"id\":\"1463\"}},\"id\":\"1459\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"ll\"},\"id\":\"1440\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1448\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"1453\"},\"dimension\":1,\"ticker\":null},\"id\":\"1456\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1457\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1517\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"source\":{\"id\":\"1438\"}},\"id\":\"1477\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1513\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1450\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1452\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"commits\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1475\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1462\",\"type\":\"HelpTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1438\"},\"glyph\":{\"id\":\"1474\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1475\"},\"selection_glyph\":null,\"view\":{\"id\":\"1477\"}},\"id\":\"1476\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1454\",\"type\":\"BasicTicker\"},{\"attributes\":{\"data\":{\"commits\":[29503,17673,1321,2316,3370,4286],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1516\"},\"selection_policy\":{\"id\":\"1517\"}},\"id\":\"1438\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1442\",\"type\":\"FactorRange\"},{\"attributes\":{\"formatter\":{\"id\":\"1513\"},\"ticker\":{\"id\":\"1454\"}},\"id\":\"1453\",\"type\":\"LinearAxis\"},{\"attributes\":{\"formatter\":{\"id\":\"1515\"},\"ticker\":{\"id\":\"1451\"}},\"id\":\"1450\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1515\",\"type\":\"CategoricalTickFormatter\"}],\"root_ids\":[\"1439\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"bf2dee23-fee2-4042-a5cb-7e56ac381a5c\",\"root_ids\":[\"1439\"],\"roots\":{\"1439\":\"edec32f7-b670-4908-8bd6-fd3232e66a66\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1439"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "Visualization_tools = df['Visualization_tools']\n",
    "Commits = df['Commits']\n",
    "# 数据源准备\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        x = Visualization_tools,\n",
    "        commits = Commits\n",
    "    )\n",
    ") # 尝试鼠标移入显示数值\n",
    "TOOLTIPS = [\n",
    "    (\"commits\",\"@commits\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=Visualization_tools,\n",
    "    plot_height=350,\n",
    "    title=\"ll\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "\n",
    "# 绘制\n",
    "# p.vbar(x=fruits,top=counts,width=0.5)\n",
    "p.vbar(x='x',top='commits',width=0.8,source=source)\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start=0 #条形最低端与x轴的距离\n",
    "# p.legend.location = \"left\"\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'Contributes'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32mE:\\anaconda\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   2645\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2646\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2647\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'Contributes'",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-22-a3bc7e95b2af>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mVisualization_tools\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Visualization_tools'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mContributes\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Contributes'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[1;31m# 数据源准备\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m source = ColumnDataSource(\n\u001b[0;32m      5\u001b[0m     data = dict(\n",
      "\u001b[1;32mE:\\anaconda\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   2798\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlevels\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2799\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_multilevel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2800\u001b[1;33m             \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2801\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mis_integer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2802\u001b[0m                 \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mE:\\anaconda\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   2646\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2647\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2648\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2649\u001b[0m         \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2650\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msize\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: 'Contributes'"
     ]
    }
   ],
   "source": [
    "Visualization_tools = df['Visualization_tools']\n",
    "Contributes = df['Contributes']\n",
    "# 数据源准备\n",
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        x = Visualization_tools,\n",
    "        contributes = Contributes\n",
    "    )\n",
    ") # 尝试鼠标移入显示数值\n",
    "TOOLTIPS = [\n",
    "    (\"contributes\",\"@contributes\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=Visualization_tools,\n",
    "    plot_height=350,\n",
    "    title=\"ll\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "\n",
    "# 绘制\n",
    "# p.vbar(x=fruits,top=counts,width=0.5)\n",
    "p.vbar(x='x',top='contributes',width=0.8,source=source)\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start=0 #条形最低端与x轴的距离\n",
    "# p.legend.location = \"left\"\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 老师代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"f8b3d46c-9c72-4918-ab09-9b2244eb6ef5\" data-root-id=\"1568\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"53a02865-3857-4977-8d8c-2481549c51dc\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1579\"}],\"center\":[{\"id\":\"1581\"},{\"id\":\"1585\"},{\"id\":\"1615\"}],\"left\":[{\"id\":\"1582\"}],\"plot_height\":500,\"renderers\":[{\"id\":\"1605\"}],\"title\":{\"id\":\"1569\"},\"toolbar\":{\"id\":\"1594\"},\"x_range\":{\"id\":\"1571\"},\"x_scale\":{\"id\":\"1575\"},\"y_range\":{\"id\":\"1573\"},\"y_scale\":{\"id\":\"1577\"}},\"id\":\"1568\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"items\":[{\"id\":\"1616\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"1615\",\"type\":\"Legend\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1586\"},{\"id\":\"1587\"},{\"id\":\"1588\"},{\"id\":\"1589\"},{\"id\":\"1590\"},{\"id\":\"1591\"},{\"id\":\"1593\"}]},\"id\":\"1594\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1611\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1612\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1589\",\"type\":\"SaveTool\"},{\"attributes\":{\"data_source\":{\"id\":\"1567\"},\"glyph\":{\"id\":\"1603\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1604\"},\"selection_glyph\":null,\"view\":{\"id\":\"1606\"}},\"id\":\"1605\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"1604\",\"type\":\"VBar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1592\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"fill_color\":{\"field\":\"color\"},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"1603\",\"type\":\"VBar\"},{\"attributes\":{\"label\":{\"field\":\"tools\"},\"renderers\":[{\"id\":\"1605\"}]},\"id\":\"1616\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1575\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1609\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1591\",\"type\":\"HelpTool\"},{\"attributes\":{\"end\":14000,\"start\":0},\"id\":\"1573\",\"type\":\"DataRange1d\"},{\"attributes\":{\"overlay\":{\"id\":\"1592\"}},\"id\":\"1588\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"data\":{\"color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"star_counts\":[9678,11034,5387,6038,4928,3783],\"tools\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1612\"},\"selection_policy\":{\"id\":\"1613\"}},\"id\":\"1567\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"axis\":{\"id\":\"1582\"},\"dimension\":1,\"ticker\":null},\"id\":\"1585\",\"type\":\"Grid\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1571\",\"type\":\"FactorRange\"},{\"attributes\":{\"axis\":{\"id\":\"1579\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1581\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1586\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1580\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"1590\",\"type\":\"ResetTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1609\"},\"ticker\":{\"id\":\"1583\"}},\"id\":\"1582\",\"type\":\"LinearAxis\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"star\",\"@star_counts\"],[\"tools\",\"@tools\"]]},\"id\":\"1593\",\"type\":\"HoverTool\"},{\"attributes\":{\"source\":{\"id\":\"1567\"}},\"id\":\"1606\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1577\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1583\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1587\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1613\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"2019 Visualization_tools Star\"},\"id\":\"1569\",\"type\":\"Title\"},{\"attributes\":{\"formatter\":{\"id\":\"1611\"},\"ticker\":{\"id\":\"1580\"}},\"id\":\"1579\",\"type\":\"CategoricalAxis\"}],\"root_ids\":[\"1568\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"53a02865-3857-4977-8d8c-2481549c51dc\",\"root_ids\":[\"1568\"],\"roots\":{\"1568\":\"f8b3d46c-9c72-4918-ab09-9b2244eb6ef5\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1568"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "#数据源准备\n",
    "source=ColumnDataSource(\n",
    "    data=dict(\n",
    "        tools=df['Visualization_tools'],\n",
    "        star_counts=df['Star'],\n",
    "        color= Spectral6  #颜色也要写到source\n",
    "    \n",
    "    )\n",
    ")\n",
    "TOOLTIPS=[\n",
    "    (\"star\",\"@star_counts\"),\n",
    "    ('tools','@tools')\n",
    "]\n",
    "# 画布准备\n",
    "p = figure(\n",
    "    x_range=df['Visualization_tools'],\n",
    "    plot_height=500,\n",
    "    title=\"2019 Visualization_tools Star\",\n",
    "    tooltips=TOOLTIPS )\n",
    "# 绘制\n",
    "p.vbar(x='tools',top='star_counts',width=0.8,color='color',source=source,legend=\"tools\")\n",
    "\n",
    "\n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "p.legend.location=\"top_center\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.y_range.end = 14000\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 分组柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 准备x轴坐标数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 将 object -->list:tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['Visualization_tools', 'Watch', 'Star', 'Fork', 'Commits',\n",
       "       'Contributors'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Visualization_tools', 'Watch', 'Star', 'Fork', 'Commits', 'Contributors']"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 元组常常在数据科学中用于 malti 复合数据（分组数据/多个层级的数据）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Star', 'Commits', 'Contributors']"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 二级数据准备 --- 对应 示例代码年份数据 （元组的第二个位置）\n",
    "vis_tools_categroy = [df.columns.tolist()[2],df.columns.tolist()[4],df.columns.tolist()[5]]\n",
    "vis_tools_categroy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 一级数据准备  （元组的第一个位置）\n",
    "df['Visualization_tools']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 列表推倒式准备 X 轴 多级数据\n",
    "x = [(tool,categroy) for tool in df['Visualization_tools'] for categroy in vis_tools_categroy]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('matplotlib', 'Star'),\n",
       " ('matplotlib', 'Commits'),\n",
       " ('matplotlib', 'Contributors'),\n",
       " ('bokeh', 'Star'),\n",
       " ('bokeh', 'Commits'),\n",
       " ('bokeh', 'Contributors'),\n",
       " ('pyecharts', 'Star'),\n",
       " ('pyecharts', 'Commits'),\n",
       " ('pyecharts', 'Contributors'),\n",
       " ('seaborn', 'Star'),\n",
       " ('seaborn', 'Commits'),\n",
       " ('seaborn', 'Contributors'),\n",
       " ('plotly', 'Star'),\n",
       " ('plotly', 'Commits'),\n",
       " ('plotly', 'Contributors'),\n",
       " ('ggplot2', 'Star'),\n",
       " ('ggplot2', 'Commits'),\n",
       " ('ggplot2', 'Contributors')]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 准备y轴坐标值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 5, 3, 1, 3, 2, 4, 3, 4, 3, 2, 4, 2, 4, 5, 4, 6, 3)"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = sum(zip(data['star'], data['conmmits'], data['contributors']), ()) # 分组求和（堆叠总数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(9678, 29503, 808, 11034, 17673, 357, 5387, 1321, 18, 6038, 2316, 98, 4928, 3370, 76, 3783, 4286, 184)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(y)\n",
    "len(y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 数据准备 ColumnDataSource"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('#99d594', '#ffffbf', '#fc8d59')"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from bokeh.palettes import Spectral3\n",
    "from bokeh.transform import factor_cmap\n",
    "Spectral3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"5b75c029-ab84-4278-b97f-ba5f564e82af\" data-root-id=\"16733\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"855ff351-5344-4be4-aaba-cdcc713bfcf4\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"16743\"}],\"center\":[{\"id\":\"16745\"},{\"id\":\"16749\"}],\"left\":[{\"id\":\"16746\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"16770\"}],\"title\":{\"id\":\"16734\"},\"toolbar\":{\"id\":\"16758\"},\"x_range\":{\"id\":\"16732\"},\"x_scale\":{\"id\":\"16739\"},\"y_range\":{\"id\":\"16737\"},\"y_scale\":{\"id\":\"16741\"}},\"id\":\"16733\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"formatter\":{\"id\":\"17183\"},\"ticker\":{\"id\":\"16747\"}},\"id\":\"16746\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"field\":\"x_axis\",\"transform\":{\"id\":\"16766\"}},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"y_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x_axis\"}},\"id\":\"16768\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"17185\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"16744\"}},\"id\":\"16743\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"17185\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"16750\"},{\"id\":\"16751\"},{\"id\":\"16752\"},{\"id\":\"16753\"},{\"id\":\"16754\"},{\"id\":\"16755\"},{\"id\":\"16757\"}]},\"id\":\"16758\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"16754\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"16755\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"17186\",\"type\":\"Selection\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"counts\",\"@y_counts\"],[\"tools\",\"@x_axis\"]]},\"id\":\"16757\",\"type\":\"HoverTool\"},{\"attributes\":{\"data_source\":{\"id\":\"16731\"},\"glyph\":{\"id\":\"16768\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"16769\"},\"selection_glyph\":null,\"view\":{\"id\":\"16771\"}},\"id\":\"16770\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"16746\"},\"dimension\":1,\"ticker\":null},\"id\":\"16749\",\"type\":\"Grid\"},{\"attributes\":{\"overlay\":{\"id\":\"16756\"}},\"id\":\"16752\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"16753\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"16747\",\"type\":\"BasicTicker\"},{\"attributes\":{\"start\":0},\"id\":\"16737\",\"type\":\"DataRange1d\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x_axis\",\"transform\":{\"id\":\"16766\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"y_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x_axis\"}},\"id\":\"16769\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"17183\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data\":{\"x_axis\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"y_counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184]},\"selected\":{\"id\":\"17186\"},\"selection_policy\":{\"id\":\"17187\"}},\"id\":\"16731\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"end\":2,\"factors\":[\"Star\",\"Commits\",\"Contributors\"],\"palette\":[\"#99d594\",\"#ffffbf\",\"#fc8d59\"],\"start\":1},\"id\":\"16766\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{},\"id\":\"16751\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"16756\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"16750\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"16744\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"17187\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"\\u53ef\\u89c6\\u5316\\u6a21\\u5757\\u5728github\\u7684\\u4f7f\\u7528\\u6570\\u636e\"},\"id\":\"16734\",\"type\":\"Title\"},{\"attributes\":{\"source\":{\"id\":\"16731\"}},\"id\":\"16771\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"16739\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"factors\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"range_padding\":0.1},\"id\":\"16732\",\"type\":\"FactorRange\"},{\"attributes\":{\"axis\":{\"id\":\"16743\"},\"ticker\":null},\"id\":\"16745\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"16741\",\"type\":\"LinearScale\"}],\"root_ids\":[\"16733\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"855ff351-5344-4be4-aaba-cdcc713bfcf4\",\"root_ids\":[\"16733\"],\"roots\":{\"16733\":\"5b75c029-ab84-4278-b97f-ba5f564e82af\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "16733"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "source = ColumnDataSource(\n",
    "    data = dict(\n",
    "        x_axis = x,\n",
    "        y_counts = y,\n",
    "    )\n",
    ")\n",
    "color=Spectral3\n",
    "\n",
    "# 点击数据 tooltips\n",
    "TOOLTIPS=[\n",
    "    (\"counts\",\"@y_counts\"),\n",
    "    (\"tools\",\"@x_axis\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range = FactorRange(*x),\n",
    "    plot_height = 350,\n",
    "    title = \"可视化模块在github的使用数据\",\n",
    "    tooltips = TOOLTIPS\n",
    ")\n",
    "\n",
    "# 绘制图形 vbar 垂直柱状图\n",
    "p.vbar(\n",
    "    x='x_axis',\n",
    "    top=\"y_counts\",\n",
    "    width=0.8,\n",
    "    source=source,\n",
    "    fill_color=factor_cmap('x_axis',palette=color,factors=vis_tools_categroy,start=1,end=2)\n",
    ")\n",
    "p.y_range.start = 0 # y轴的起始值\n",
    "p.x_range.range_padding = 0.1 # 边距\n",
    "p.xaxis.major_label_orientation = 1\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"6aedf3fa-b4ea-438d-ad0b-3f2587166610\" data-root-id=\"11265\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"3bad2248-8150-45a9-b09d-4687a3385790\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"11275\"}],\"center\":[{\"id\":\"11277\"},{\"id\":\"11281\"}],\"left\":[{\"id\":\"11278\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"11299\"}],\"title\":{\"id\":\"11266\"},\"toolbar\":{\"id\":\"11289\"},\"x_range\":{\"id\":\"11264\"},\"x_scale\":{\"id\":\"11271\"},\"y_range\":{\"id\":\"11269\"},\"y_scale\":{\"id\":\"11273\"}},\"id\":\"11265\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"11619\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"11616\"},\"ticker\":{\"id\":\"11279\"}},\"id\":\"11278\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"11275\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"11277\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"11286\",\"type\":\"ResetTool\"},{\"attributes\":{\"factors\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]],\"range_padding\":0.1},\"id\":\"11264\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"11616\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"overlay\":{\"id\":\"11288\"}},\"id\":\"11284\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"formatter\":{\"id\":\"11618\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"11276\"}},\"id\":\"11275\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"11271\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"11287\",\"type\":\"HelpTool\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"11266\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"11273\",\"type\":\"LinearScale\"},{\"attributes\":{\"data_source\":{\"id\":\"11263\"},\"glyph\":{\"id\":\"11297\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"11298\"},\"selection_glyph\":null,\"view\":{\"id\":\"11300\"}},\"id\":\"11299\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"11298\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"11620\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"11297\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"11278\"},\"dimension\":1,\"ticker\":null},\"id\":\"11281\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"11282\",\"type\":\"PanTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"11282\"},{\"id\":\"11283\"},{\"id\":\"11284\"},{\"id\":\"11285\"},{\"id\":\"11286\"},{\"id\":\"11287\"}]},\"id\":\"11289\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"11285\",\"type\":\"SaveTool\"},{\"attributes\":{\"source\":{\"id\":\"11263\"}},\"id\":\"11300\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"11276\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"11618\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"11283\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"11279\",\"type\":\"BasicTicker\"},{\"attributes\":{\"start\":0},\"id\":\"11269\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data\":{\"counts\":[2,5,3,1,3,2,4,3,4,3,2,4,2,4,5,4,6,3],\"x\":[[\"Apples\",\"2015\"],[\"Apples\",\"2016\"],[\"Apples\",\"2017\"],[\"Pears\",\"2015\"],[\"Pears\",\"2016\"],[\"Pears\",\"2017\"],[\"Nectarines\",\"2015\"],[\"Nectarines\",\"2016\"],[\"Nectarines\",\"2017\"],[\"Plums\",\"2015\"],[\"Plums\",\"2016\"],[\"Plums\",\"2017\"],[\"Grapes\",\"2015\"],[\"Grapes\",\"2016\"],[\"Grapes\",\"2017\"],[\"Strawberries\",\"2015\"],[\"Strawberries\",\"2016\"],[\"Strawberries\",\"2017\"]]},\"selected\":{\"id\":\"11619\"},\"selection_policy\":{\"id\":\"11620\"}},\"id\":\"11263\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"11288\",\"type\":\"BoxAnnotation\"}],\"root_ids\":[\"11265\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"3bad2248-8150-45a9-b09d-4687a3385790\",\"root_ids\":[\"11265\"],\"roots\":{\"11265\":\"6aedf3fa-b4ea-438d-ad0b-3f2587166610\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "11265"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "## 构建一对多的关系\n",
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']\n",
    "years = ['2015', '2016', '2017']\n",
    "data = {'fruits' : fruits,\n",
    "        '2015'   : [2, 1, 4, 3, 2, 4],\n",
    "        '2016'   : [5, 3, 3, 2, 4, 6],\n",
    "        '2017'   : [3, 2, 4, 4, 5, 3]}\n",
    "\n",
    "x = [ (fruit, year) for fruit in fruits for year in years ]\n",
    "counts = sum(zip(data['2015'], data['2016'], data['2017']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 课后实践（star，commits，contributes）分组柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"725b07b9-2295-4822-af34-f3a63aedd8fb\" data-root-id=\"10497\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"c8e2d987-c991-4c00-9f18-dcd6522ecf51\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"10507\"}],\"center\":[{\"id\":\"10509\"},{\"id\":\"10513\"}],\"left\":[{\"id\":\"10510\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"10533\"}],\"title\":{\"id\":\"10498\"},\"toolbar\":{\"id\":\"10522\"},\"x_range\":{\"id\":\"10496\"},\"x_scale\":{\"id\":\"10503\"},\"y_range\":{\"id\":\"10501\"},\"y_scale\":{\"id\":\"10505\"}},\"id\":\"10497\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"formatter\":{\"id\":\"10842\"},\"ticker\":{\"id\":\"10511\"}},\"id\":\"10510\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"10519\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"10514\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"10508\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"overlay\":{\"id\":\"10520\"}},\"id\":\"10516\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"source\":{\"id\":\"10495\"}},\"id\":\"10534\",\"type\":\"CDSView\"},{\"attributes\":{\"data_source\":{\"id\":\"10495\"},\"glyph\":{\"id\":\"10531\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"10532\"},\"selection_glyph\":null,\"view\":{\"id\":\"10534\"}},\"id\":\"10533\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"10842\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"10844\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"10508\"}},\"id\":\"10507\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"axis\":{\"id\":\"10510\"},\"dimension\":1,\"ticker\":null},\"id\":\"10513\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"10511\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"10844\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"start\":0},\"id\":\"10501\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"10517\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"10845\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"10515\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"star\",\"@star\"],[\"conmmits\",\"@conmmits\"],[\"contributors\",\"@contributors\"]]},\"id\":\"10521\",\"type\":\"HoverTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"10531\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"10507\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"10509\",\"type\":\"Grid\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"conmmits\"],[\"matplotlib\",\"contributors\"],[\"bokeh\",\"star\"],[\"bokeh\",\"conmmits\"],[\"bokeh\",\"contributors\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"conmmits\"],[\"pyecharts\",\"contributors\"],[\"seaborn\",\"star\"],[\"seaborn\",\"conmmits\"],[\"seaborn\",\"contributors\"],[\"plotly\",\"star\"],[\"plotly\",\"conmmits\"],[\"plotly\",\"contributors\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"conmmits\"],[\"ggplot2\",\"contributors\"]],\"range_padding\":0.1},\"id\":\"10496\",\"type\":\"FactorRange\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"10498\",\"type\":\"Title\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"10520\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"conmmits\"],[\"matplotlib\",\"contributors\"],[\"bokeh\",\"star\"],[\"bokeh\",\"conmmits\"],[\"bokeh\",\"contributors\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"conmmits\"],[\"pyecharts\",\"contributors\"],[\"seaborn\",\"star\"],[\"seaborn\",\"conmmits\"],[\"seaborn\",\"contributors\"],[\"plotly\",\"star\"],[\"plotly\",\"conmmits\"],[\"plotly\",\"contributors\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"conmmits\"],[\"ggplot2\",\"contributors\"]]},\"selected\":{\"id\":\"10845\"},\"selection_policy\":{\"id\":\"10846\"}},\"id\":\"10495\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"10532\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"10518\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"10503\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"10514\"},{\"id\":\"10515\"},{\"id\":\"10516\"},{\"id\":\"10517\"},{\"id\":\"10518\"},{\"id\":\"10519\"},{\"id\":\"10521\"}]},\"id\":\"10522\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"10846\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"10505\",\"type\":\"LinearScale\"}],\"root_ids\":[\"10497\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"c8e2d987-c991-4c00-9f18-dcd6522ecf51\",\"root_ids\":[\"10497\"],\"roots\":{\"10497\":\"725b07b9-2295-4822-af34-f3a63aedd8fb\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "10497"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "## 构建一对多的关系\n",
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "from bokeh.transform import factor_cmap\n",
    "fruits = df['Visualization_tools']\n",
    "groups = ['star', 'conmmits', 'contributors']\n",
    "data = {'fruits' : fruits,\n",
    "        'star'   : df['Star'],\n",
    "        'conmmits'   : df['Commits'],\n",
    "        'contributors'   : df['Contributors']}\n",
    "\n",
    "x = [ (fruit, group) for fruit in fruits for group in groups ]\n",
    "counts = sum(zip(data['star'], data['conmmits'], data['contributors']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "TOOLTIPS=[\n",
    "    (\"star\",\"@star\"),\n",
    "    (\"conmmits\",\"@conmmits\"),\n",
    "    (\"contributors\",\"@contributors\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=FactorRange(*x),\n",
    "    plot_height=350, \n",
    "    title=\"Fruit Counts by Year\",\n",
    "    tooltips=TOOLTIPS\n",
    ")\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9,source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"3ac69f16-7624-4b91-a70e-e01dbe9caf22\" data-root-id=\"10497\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"23db3e7a-6214-40b2-9ccb-a99b2d29bceb\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"10507\"}],\"center\":[{\"id\":\"10509\"},{\"id\":\"10513\"}],\"left\":[{\"id\":\"10510\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"10533\"},{\"id\":\"10900\"}],\"title\":{\"id\":\"10498\"},\"toolbar\":{\"id\":\"10522\"},\"x_range\":{\"id\":\"10496\"},\"x_scale\":{\"id\":\"10503\"},\"y_range\":{\"id\":\"10501\"},\"y_scale\":{\"id\":\"10505\"}},\"id\":\"10497\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"formatter\":{\"id\":\"10842\"},\"ticker\":{\"id\":\"10511\"}},\"id\":\"10510\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"10896\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"10899\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"10519\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"10514\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"10508\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"source\":{\"id\":\"10495\"}},\"id\":\"10534\",\"type\":\"CDSView\"},{\"attributes\":{\"overlay\":{\"id\":\"10520\"}},\"id\":\"10516\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"data_source\":{\"id\":\"10495\"},\"glyph\":{\"id\":\"10531\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"10532\"},\"selection_glyph\":null,\"view\":{\"id\":\"10534\"}},\"id\":\"10533\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data_source\":{\"id\":\"10495\"},\"glyph\":{\"id\":\"10898\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"10899\"},\"selection_glyph\":null,\"view\":{\"id\":\"10901\"}},\"id\":\"10900\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"10842\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"10844\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"10508\"}},\"id\":\"10507\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"axis\":{\"id\":\"10510\"},\"dimension\":1,\"ticker\":null},\"id\":\"10513\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"10511\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"10844\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"10495\"}},\"id\":\"10901\",\"type\":\"CDSView\"},{\"attributes\":{\"start\":0},\"id\":\"10501\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"10517\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"10845\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"10515\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"star\",\"@star\"],[\"conmmits\",\"@conmmits\"],[\"contributors\",\"@contributors\"]]},\"id\":\"10521\",\"type\":\"HoverTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"10531\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"10507\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"10509\",\"type\":\"Grid\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"conmmits\"],[\"matplotlib\",\"contributors\"],[\"bokeh\",\"star\"],[\"bokeh\",\"conmmits\"],[\"bokeh\",\"contributors\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"conmmits\"],[\"pyecharts\",\"contributors\"],[\"seaborn\",\"star\"],[\"seaborn\",\"conmmits\"],[\"seaborn\",\"contributors\"],[\"plotly\",\"star\"],[\"plotly\",\"conmmits\"],[\"plotly\",\"contributors\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"conmmits\"],[\"ggplot2\",\"contributors\"]],\"range_padding\":0.1},\"id\":\"10496\",\"type\":\"FactorRange\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"10498\",\"type\":\"Title\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"10896\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"10898\",\"type\":\"VBar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"10520\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"conmmits\"],[\"matplotlib\",\"contributors\"],[\"bokeh\",\"star\"],[\"bokeh\",\"conmmits\"],[\"bokeh\",\"contributors\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"conmmits\"],[\"pyecharts\",\"contributors\"],[\"seaborn\",\"star\"],[\"seaborn\",\"conmmits\"],[\"seaborn\",\"contributors\"],[\"plotly\",\"star\"],[\"plotly\",\"conmmits\"],[\"plotly\",\"contributors\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"conmmits\"],[\"ggplot2\",\"contributors\"]]},\"selected\":{\"id\":\"10845\"},\"selection_policy\":{\"id\":\"10846\"}},\"id\":\"10495\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"10532\",\"type\":\"VBar\"},{\"attributes\":{\"end\":2,\"factors\":[\"star\",\"conmmits\",\"contributors\"],\"palette\":[\"#c9d9d3\",\"#718dbf\",\"#e84d60\"],\"start\":1},\"id\":\"10896\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{},\"id\":\"10518\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"10503\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"10514\"},{\"id\":\"10515\"},{\"id\":\"10516\"},{\"id\":\"10517\"},{\"id\":\"10518\"},{\"id\":\"10519\"},{\"id\":\"10521\"}]},\"id\":\"10522\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"10846\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"10505\",\"type\":\"LinearScale\"}],\"root_ids\":[\"10497\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"23db3e7a-6214-40b2-9ccb-a99b2d29bceb\",\"root_ids\":[\"10497\"],\"roots\":{\"10497\":\"3ac69f16-7624-4b91-a70e-e01dbe9caf22\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "10497"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "## 增加分组柱状图颜色\n",
    "from bokeh.transform import factor_cmap\n",
    "\n",
    "palette = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "\n",
    "# 绘图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source, line_color=\"white\",\n",
    "       fill_color=factor_cmap('x', palette=palette, factors=groups, start=1, end=2))\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
